package com.shuai.AI.ai_app.rag.config;

import com.shuai.AI.ai_app.readers.LoveAppDocumentReader;
import jakarta.annotation.Resource;
import java.util.List;
import org.springframework.ai.document.Document;
import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.vectorstore.SimpleVectorStore;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/** 恋爱大师向量数据库配置（初始化基于内存的向量数据库 Bean） */
@Configuration
public class LoveAppSimpleVectorStoreConfig {

  @Resource private LoveAppDocumentReader loveAppDocumentReader;

  //    @Resource
  //    private MyTokenTextSplitter myTokenTextSplitter;

  //  @Resource private MyKeywordEnricher myKeywordEnricher;

  @Bean
  VectorStore loveAppSimpleVectorStore(EmbeddingModel dashscopeEmbeddingModel) {
    VectorStore simpleVectorStore =
        SimpleVectorStore.builder(dashscopeEmbeddingModel).build();
    // 加载文档
    List<Document> documentList = loveAppDocumentReader.loadMarkdowns();
    simpleVectorStore.add(documentList);
    // 自主切分文档(这个是按照token进行分割，一般不建议使用，分割的内容很乱)
    //        List<Document> splitDocuments = myTokenTextSplitter.splitCustomized(documentList);
    // 自动补充关键词元信息（这个会再一次调用ai，会消耗更多的token）
    //    List<Document> enrichedDocuments = myKeywordEnricher.enrichDocuments(documentList);
    //    simpleVectorStore.add(enrichedDocuments);
    return simpleVectorStore;
  }
}
